package com.oracle.controller;

import com.oracle.pojo.Comment;
import com.oracle.pojo.News;
import com.oracle.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.time.LocalDateTime;

@Controller
public class CommentController {
    @Autowired
    private CommentService commentService;

    @RequestMapping(value = "/addComment/{nid}",method = RequestMethod.POST)
    public String getAllNews(@PathVariable Integer nid, String content,Integer uid){
        Comment comment = new Comment();
        comment.setNid(nid);
        comment.setContent(content);
        comment.setCreateTime(LocalDateTime.now());
        if (uid==null){
            comment.setUid(2);
        }else {
            comment.setUid(uid);
        }
        commentService.addComment(comment);
        return "redirect:/checkNews/"+nid;
    }
}
